package com.zhou.system.management.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.zhou.common.lib.model.Response;
import com.zhou.system.management.entity.SysMenu;
import com.zhou.system.management.model.vo.SysMenuAddVo;
import com.zhou.system.management.model.vo.SysMenuTreeVo;
import com.zhou.system.management.model.vo.SysMenuUpdateVo;
import com.zhou.system.management.service.impl.SysMenuServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 系统菜单表 前端控制器
 * </p>
 *
 * @author zxf
 * @since 2023-05-18
 */
@Api(tags = "菜单模块")
@ApiSupport(order = 1)
@RestController
@RequestMapping("/sys-menu")
public class SysMenuController {

    @Autowired
    private SysMenuServiceImpl menuService;

    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "查询系统菜单")
    @PostMapping("/query")
    public Response<List<SysMenu>> test() {
        LambdaQueryWrapper<SysMenu> queryWrapper = Wrappers.<SysMenu>lambdaQuery()
                .orderByAsc(SysMenu::getOrderNum)
                .orderByAsc(SysMenu::getMenuId);
        List<SysMenu> list = menuService.list(queryWrapper);
        return Response.success(list);
    }

    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "查询菜单树")
    @PostMapping("/tree/query")
    public Response<List<SysMenuTreeVo>> queryMenuTree() {
        List<SysMenuTreeVo> list = menuService.queryMenuTree();
        return Response.success(list);
    }

    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "新增菜单")
    @PostMapping("/add")
    public Response<String> add(@RequestBody SysMenuAddVo addVo) {
        menuService.add(addVo);
        return Response.success();
    }

    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "更新菜单")
    @PostMapping("/update")
    public Response<String> update(@RequestBody SysMenuUpdateVo updateVo) {
        menuService.update(updateVo);
        return Response.success();
    }

    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "删除菜单")
    @DeleteMapping("/{menuId}")
    public Response<String> delete(@PathVariable Long menuId) {
        menuService.removeById(menuId);
        return Response.success();
    }
}
